// const { city_name } = require("/public/config/config");

// console.log("process.env.NODE_ENV: ", process.env.NODE_ENV);
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (elt) {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = from < 0 ? Math.ceil(from) : Math.floor(from);
    if (from < 0) from += len;
    for (; from < len; from++) {
      if (from in this && this[from] === elt) return from;
    }
    return -1;
  };
}
var baseUrl = "/wycms-api";

var yc_duty = {};
function handleResponse(res) {
  yc_duty = res.data;
  var s = "";
  if (["yc"].indexOf(-1)) {
    s += '<span class="container">';
    for (var index = 0; index < yc_duty.length; index++) {
      var item = yc_duty[index];
      s += ` <span class="item">
        <p class="name"> 第${toChineseNumeral(index + 1)}值班人 ${
        item.dutypeople1
      } </p>
        <span class="phone"> 电话：${item.phone} </span>
        <span class="tel"> 手机号：${item.tel} </span>
        </span>`;
    }

    s += "</span>";
  }
  $("#app").append(s);
}
function getZhiban(name) {
  let query = getQuery();

  $.ajax({
    url: baseUrl + "/customize/duty/indexYc",
    method: "post",
    data: { siteId: query.siteId },
    success: handleResponse,
  });
}
function toChineseNumeral(num) {
  const digits = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
  const units = ["", "十", "百", "千", "万"];

  let result = "";
  let numStr = String(num);

  for (let i = 0; i < numStr.length; i++) {
    let digit = parseInt(numStr.charAt(i));
    let unit = units[numStr.length - i - 1];
    if (digit === 0 && unit !== "万" && unit !== "") {
      // 如果当前数字是0，并且不是万位或个位，则不需要添加零
      continue;
    }
    result += digits[digit] + unit;
  }

  return result;
}
getZhiban();
